package com.adong.onecoupon.framework.exception;

/**
 * 抽象项目中三类异常体系，客户端异常、服务端异常以及远程服务调用异常
 */
import com.adong.onecoupon.framework.errorcode.IErrorCode;
import lombok.Getter;
import org.springframework.util.StringUtils;

import java.util.Optional;

@Getter
public abstract class AbstractException extends RuntimeException{
    public final String errorCode;
    public final String errorMessage;

    public AbstractException(String errorMessage, Throwable throwable, IErrorCode errorCode) {
        super(errorMessage,throwable);
        this.errorCode = errorCode.code();
        this.errorMessage = Optional.ofNullable(StringUtils.hasLength(errorMessage)?errorMessage:null).orElse(errorCode.message());
    }
}
